<?php

/*
this file is just for testing purposes and getting to know the
WikiData/OmegaWiki database scheme. Old and new code will be flying around,
getting commented, deleted, moved etc. Eventually, when I decide what exactly I
want to do and how, and implement it in a more useful place, this file will
be deleted.
*/

require_once('../db.inc.php');
require_once('../common.inc.php');

xmlhead("Dumping DM's with their associated Expressions");

echo "<body>\n";

$dbh = get_db();

$source_language_id = 85;
$target_language_id = 102;

$language_names = getAsocArr("language_names", "language_id", "language_name", $dbh, "name_language_id = $source_language_id");

/*
echo "<!--\n";
var_dump($language_names);
echo "-->\n";
*/

echo "source: {$language_names[$source_language_id]} ($source_language_id) / target: {$language_names[$target_language_id]} ($target_language_id)<br />\n";

/*
$query = do_query(
	"SELECT *
	FROM uw_defined_meaning dm, text, uw_translated_content tc
	WHERE dm.meaning_text_tcid = tc.translated_content_id
	AND text.old_id = tc.text_id
	AND dm.remove_transaction_id IS NULL
	AND tc.remove_transaction_id IS NULL
	AND old_flags != 'utf-8'
	AND tc.language_id = $pref_lang_id
	ORDER BY defined_meaning_id ASC
	LIMIT $start,$step
	", $dbh);
*/

//get all DM's with an expression in the source lang
$query = do_query(
	"SELECT defined_meaning_id, spelling
	FROM uw_syntrans st, uw_expression ex
	WHERE st.expression_id = ex.expression_id
	AND ex.language_id = $source_language_id
	AND identical_meaning = 1
	GROUP BY defined_meaning_id
	", $dbh);

$i = 1;
while ($row = mysql_fetch_array($query)) {
	//get all DM's that also have an expression in the target lang
	$query2 = do_query(
		"SELECT defined_meaning_id, spelling
		FROM uw_syntrans st, uw_expression ex
		WHERE st.expression_id = ex.expression_id
		AND st.defined_meaning_id = {$row['defined_meaning_id']}
		AND ex.language_id = $target_language_id
		AND identical_meaning = 1
		LIMIT 1;
		", $dbh);
	while (($i <= 100) && $row2 = mysql_fetch_array($query2)) {
		$i++;
		echo "{$row2['defined_meaning_id']} occurs both in {$language_names[$source_language_id]} (as <i>{$row['spelling']}</i>) and {$language_names[$target_language_id]} (as <i>{$row2['spelling']}</i>)<br />\n";
	}
}

/*
while ($row = mysql_fetch_array($query)) {
	echo "<a href=\"/wikidata/index.php?title=DefinedMeaning:({$row['defined_meaning_id']})\">{$row['defined_meaning_id']}</a> in {$language_names[$row['language_id']]}: {$row['old_text']}<br /><br />";
	$subquery = do_query(
	"SELECT *
	FROM uw_syntrans st, uw_expression ex
	WHERE st.expression_id = ex.expression_id
	AND defined_meaning_id = {$row['defined_meaning_id']}
	AND identical_meaning = 1
	AND st.remove_transaction_id IS NULL
	AND ex.remove_transaction_id IS NULL
	ORDER BY language_id
	", $dbh);
	while ($subrow = mysql_fetch_array($subquery)) {
		echo "{$language_names[$subrow['language_id']]}: <a href=\"/wikidata/index.php?title=Expression:{$subrow['spelling']}\">{$subrow['spelling']}</a> ";
	}
	echo "<br /><br />\n";
}
*/

?>
</body>
</html>